1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use super::*;
pub fn primitive(input: &str) -> IResult<&str, Expr> {
alt((
map(natural, Expr::Natural),
map(tag(EMPTY), |_| Expr::Empty),
map(tag(UNIT), |_| Expr::Unit),
map(tag(NAT), |_| Expr::Nat),
map(tag(BOOL), |_| Expr::Bool),
map(boolean, Expr::Boolean),
))(input)
}
pub fn natural(input: &str) -> IResult<&str, BigUint> {
alt((
map_opt(preceded(tag("0x"), hex_digit1), |digits: &str| {
BigUint::parse_bytes(digits.as_bytes(), 16)
}),
map_opt(preceded(tag("0o"), oct_digit1), |digits: &str| {
BigUint::parse_bytes(digits.as_bytes(), 8)
}),
map_opt(preceded(tag("0b"), is_a("01")), |digits: &str| {
BigUint::parse_bytes(digits.as_bytes(), 2)
}),
map_opt(digit1, |digits: &str| {
BigUint::parse_bytes(digits.as_bytes(), 10)
}),
))(input)
}